import { weBtoa } from '../../utils/arraybuffer2img/weapp-jwt'

// ArrayBuffer转16进制字符串示例
function ab2hex(buffer) {
  let hexArr = Array.prototype.map.call(
    new Uint8Array(buffer),
    function(bit) {
      return ('00' + bit.toString(16)).slice(-2)
    }
  )
  return hexArr.join('');
}

// 十六进制转为base64
function hexToBase64(hexstring) {
  return weBtoa(hexstring.match(/\w{2}/g).map(function(a) {
      return String.fromCharCode(parseInt(a, 16));
  }).join(""));
}

module.exports = {
  ab2hex: ab2hex, 
  hexToBase64: hexToBase64
}